<?php

/**
 * Ucenik filter form.
 *
 * @package    dnevnik
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterTemplate.php 11675 2008-09-19 15:21:38Z fabien $
 */
class UcenikFormFilter extends BaseUcenikFormFilter
{
  public function configure()
  {
      // TO DO - smotano citanje sesije
      //$holder = sfContext::getInstance()->getUser()->getAttributeHolder()->getNames('ucenik.filters');
      $skola_id = isset($_SESSION['symfony/user/sfUser/attributes']['admin_module']['ucenik.filters']['skola_id']) ? $_SESSION['symfony/user/sfUser/attributes']['admin_module']['ucenik.filters']['skola_id'] : NULL;
      $this->offsetUnset('datum_rod');
      $this->offsetUnset('mesto_rod');
      $this->offsetUnset('opstina_rod');
      $this->offsetUnset('drzava_rod');
      $this->offsetUnset('tip');
      $this->offsetUnset('red_br');
      $this->offsetUnset('maticna_kn');
      $this->offsetUnset('delovodni_br');
      $this->offsetUnset('azuriran');
      $this->offsetUnset('jmbg');
      $this->offsetUnset('ucenik_razred_list');

      $this->setWidget('roditelj_id', new sfWidgetFormPropelChoice(array('model' => 'Roditelj', 'add_empty' => true)));
      $this->widgetSchema['roditelj_id']->setOption('renderer_class', 'sfWidgetFormPropelJQueryAutocompleter');
      $this->widgetSchema['roditelj_id']->setOption('renderer_options', array(
        'model' => 'Roditelj',
        'url'   => '/backend.php/roditelj/ajaxList?skola_id='.$skola_id,  //$this->getObject()->getSkolaId(),
      ));

      $this->widgetSchema['username'] = new sfWidgetFormFilterInput();
      $this->validatorSchema['username'] = new sfValidatorPass(array('required' => false));
      $this->widgetSchema['prezime'] = new sfWidgetFormFilterInput();
      $this->validatorSchema['prezime'] = new sfValidatorPass(array('required' => false));
      $this->widgetSchema['ime'] = new sfWidgetFormFilterInput();
      $this->validatorSchema['ime'] = new sfValidatorPass(array('required' => false));
  }

  public function getFields()
  {
    return array_merge(array(
        'username' => 'Username',
        'prezime' => 'Prezime',
        'ime' => 'Ime',
      ), parent::getFields()
    );
  }

  protected function addUsernameColumnCriteria(Criteria $criteria, $field, $values)
  {
      $criteria->addJoin(UcenikPeer::ID , ProfilPeer::ID);
      $criteria->add(ProfilPeer::USERNAME, '%'.$values['text'].'%', Criteria::LIKE);
  }

  protected function addPrezimeColumnCriteria(Criteria $criteria, $field, $values)
  {
      $criteria->addJoin(UcenikPeer::ID , ProfilPeer::ID);
      $criteria->add(ProfilPeer::PREZIME, '%'.$values['text'].'%', Criteria::LIKE);
  }

  protected function addImeColumnCriteria(Criteria $criteria, $field, $values)
  {
      $criteria->addJoin(UcenikPeer::ID , ProfilPeer::ID);
      $criteria->add(ProfilPeer::IME, '%'.$values['text'].'%', Criteria::LIKE);
  }
}